# Setting compilation variables and changes it to an environment variable
CROSS_COMPILE = 
AS    = $(CROSS_COMPILE)as
LD    = $(CROSS_COMPILE)ld
CC    = $(CROSS_COMPILE)gcc
CPP   = $(CC) -E
AR    = $(CROSS_COMPILE)ar
NM    = $(CROSS_COMPILE)nm

STRIP    = $(CROSS_COMPILE)strip
OBJCOPY  = $(CROSS_COMPILE)objcopy
OBJDUMP  = $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP

# Setting compilation parameters
CFLAGS := -Wall -O2 -g
CFLAGS += -I $(shell pwd)/include

# Setting up the link library
LDFLAGS := 

export CFLAGS LDFLAGS

# Home directory location
MASDIR := $(shell pwd)
export MASDIR

# Target run file
TARGET := test

# Subdirectory and the files in this directory to be compiled
objs += main.o a/ 

# The primary target of the Makefile
all : build_makefile $(TARGET)
	@echo $(TARGET) has been built!

# The compile location is in this directory, and the compiled file is makefile.bulid
build_makefile :
	make -C ./ -f $(MASDIR)/Makefile.build

# Finally the target file links to the library
$(TARGET) : build_all.o $(LDFLAGS)
	$(CC) -o $@ build_all.o $(LDFLAGS)

.PHONY : clean

clean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")

